<?php
/**
 * @category Account
 * @package Account_Lib
 * @subpackage EventHandler
 */
class Account_Lib_EventHandler_Account_Account_CreateNewAccountInDatabase 
    extends Account_Lib_EventHandler_Logger 
    implements Oxy_EventStore_EventHandler_EventHandlerInterface
{
	/**
     * @see Oxy_EventStore_EventHandler_EventHandlerInterface::handle()
     */
    public function handle(Oxy_EventStore_Event_EventInterface $event)
    {   
        $data = array(
            '_id' => $event->getAccountGuid(),
            'primaryEmail' => $event->getPrimaryEmail(),
            'password' => $event->getEncodedPassword(),
            'date' => $event->getDate(),
            'lastResurectDate' => '',
            'state' => $event->getState(),
            'personalInformation' => $event->getPersonalInformation(),
            'deliveryInformation' => $event->getDeliveryInformation(),
            'settings' => $event->getSettings(),
            'activationKey' => $event->getEmailActivationKey(),
            'loginState' => $event->getLoginState(),
            'generatedPassword' => $event->getGeneratedPassword(),
            'isAutoGenerated' => $event->getIsAutoGenerated()
        );
                
        try{  
            $this->_insertData($data, Account_Lib_Query_AccountInformation::ACCOUNT_COLLECTION);
        } catch (MongoCursorException $ex){
            $this->_log(
                get_class($this), 
                array(
                    'message' => $ex->getMessage(),
                    'trace' => $ex->getTrace(),
                    'code' => $ex->getCode(),
                ), 
                parent::ERROR_LEVEL_EXCEPTION
            );
        }
    } 
}
